home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / MCGA_TUT.ZIP / MCGA.02 < prev    next >
Encoding:
Text File  |  1995-08-31  |  6.6 KB  |  126 lines

  1. -------------------------------------------------------------------------------
  2. Nachricht Nr. 0234 aus Area PASCAL.GER   Exportiert mit Yuppie! v2.10
  3. -------------------------------------------------------------------------------
  4. Datum: 02 Jul 92  09:11:42
  5. Von  : Thomas Karp                            
  6. An   : All                                    
  7. Betr.: MCGA Tutorial v. James Cook                                         
  8. -------------------------------------------------------------------------------
  9. Hallo all....
  10. In der Area PASCAL hat vor einiger Zeit James Cook ein Tutorial fuer die
  11. Nutzung des MCGA-Modus geschrieben. Es ist zwar english (ich hab' auch erst
  12. nachgefragt) aber leicht verstaendlich. Also lass ich die Teile mal folgen:)
  13. ----------------------------------------------------------------------------
  14.  
  15. Von  : James Cook                             
  16. An   : All                                    
  17. Betr.: MCGA Tutorial #2                                                    
  18.  
  19.                            MCGA Graphics Tutorial
  20.                                  Lesson #2
  21.                                 by Jim Cook
  22.  
  23. I have to apologize a little bit.  The first lesson contained code for
  24. setting a pixel by directly altering video memory.  This probably was a
  25. strange sight for those of you that do not understand video memory, how
  26. it's layed out and how to address it.  I do hope you did get excited by
  27. workable code in the first lesson.
  28.  
  29. Video memory in the MCGA Mode we are using is far simpler to understand
  30. than even Text mode display memory.  Those of you that know all about
  31. text screen addressing, just scoffed.  No, seriously, it is easier.  I
  32. will try to make this easy to understand, because it really is.
  33.  
  34. There is a section of memory in your computer that holds the
  35. communications program you run.  There is a section of memory that holds
  36. COMMAND.COM.  There is also a section of memory that holds the video
  37. buffer.  Unlike COMMAND.COM and the comm program, whose starting address
  38. in memory could be different depending on your system, video memory is
  39. always at the same location.  In MCGA mode, video memory begins at the
  40. 655,360th byte of computer memory.  You may say that my computer only
  41. has 655,360 bytes of memory total (640K).  Where does that memory
  42. reside?  Don't quote me on this, but I beleive the memory resides on
  43. your graphics card.
  44.  
  45. So, the graphics card is responsible for scanning this piece of memory
  46. many times per second, and displaying on the screen whatever color
  47. values are stored starting at byte 655,360.  By the way, in hex (base 16)
  48. that number is $A0000, and we'll refer to it like that from now on.
  49. These color values that I referred to are numbers from 0 to 255.  If we
  50. store the number 0 in every byte of screen memory and the computer
  51. thinks that 0 means black, which it usually does, the screen will
  52. instantly clear to black.  That's how you do a screen clear in MCGA.
  53.  
  54. The resolution of our screen is 320 pixels horizontal by 200 pixels
  55. vertical.  That makes up a total of 64000 pixels per screen.  A normal
  56. text screen only has 4000 bytes of screen memory, so you can see why we
  57. sometimes use assembly language.  So, a very prehistoric screen clear
  58. procedure could look something like:
  59.  
  60.                 Procedure ClearScreen (Color:Byte);
  61.                 var
  62.                   I  :  Word;
  63.                 begin
  64.                   For I := 0 to 64000 do
  65.                     Mem [$A000:I] := Color;
  66.                 end;
  67.  
  68. You'll notice I had to break the number $A0000 into two numbers.  This
  69. is called segment-offset addressing, and it is a throwback to the days
  70. when the engineers felt we would never need more than 640K of memory.
  71. Let me briefly explain.  The memory address $A0000 and $A000:0000 are
  72. synonymous.  To compute a virtual address from a seg:ofs address you
  73. perform the calcualtion: virtual := seg * 16 + ofs.  This lets a
  74. programmer access over 1 meg of memory using 2 word size values.  Don't
  75. ask...
  76.  
  77. OK.  Since we are pretty much all hackers at heart and I don't have a
  78. chalkboard, I'll illustrate video memory:
  79.               0   1   2   3   4   5   --->  up to pixel 319
  80.             +---+---+---+---+---+---+---+---+---+---+---+---+--
  81.         0   + 0 | 1 | 2 | 3 | 4 | 5 |   |   |   |   |   |   |
  82.             +---+---+---+---+---+---+---+---+---+---+---+---+--
  83.         1   +320|321|322|323|324|   |   |   |   |   |   |   |
  84.             +---+---+---+---+---+---+---+---+---+---+---+---+--
  85.         2   +640|641|642|643|   |   |   |   |   |   |   |   |
  86.             +---+---+---+---+---+---+---+---+---+---+---+---+--
  87.         3   +   |   |   |   |   |   |   |   |   |   |   |   |
  88.  
  89. Assume, (I know, bad word), that this is a extreme closeup of the upper
  90. left corner of a MCGA screen.  As a matter of fact the box 0 is the
  91. first pixel (the uppermost leftest most pixel) on the screen.  Say, we
  92. want to make it white.  In the default palette the color white is 255.
  93. All we have to do is say:       Mem [$A000:0000] := 255;
  94. If we want to make the pixel below it white also, we type :
  95.                                 Mem [$A000:0320] := 255;
  96. As you can see, segment:offset addressing actually comes in handy in
  97. addressing pixels on the screen.  Since there are 320 pixels across and
  98. 200 Pixels up and down, the following formula returns the address of any
  99. pixel on the MCGA screen:       (Y * 320) + X
  100. This is assuming the upperleft pixel is (0,0) and the lower right pixel
  101. is (319,199), and we will.
  102.  
  103. Understanding screen addresses is essential to comprehending any of the
  104. code we will be developing, so if a point is not clear...POST a message.
  105. Don't be bashful about asking questions.  Just a quick point...I did not
  106. go to school to learn this.  This is something everyone can learn.
  107. Graphics is a subject that a lot gets written about, but not the guts of
  108. programming it.  Many of you may opt for the easy way out (canned
  109. libraries) but to really understand your computer you have to know
  110. what's going on under the hood.  Also, for laughs, try implementing a
  111. good animation program or GUI with the BGI.
  112.  
  113. hack on
  114. jim
  115. ----------------------------------------------------------------------------
  116. weitere Teile folgen.
  117.  
  118. --- Yuppie! v2.10
  119.  * Origin: ...:-)..alles eine Frage des richtigen Fehlers... (2:245/555.10)
  120. SEEN-BY: 241/2 2000 4000 4150 4500 5000 5100 5300 5600 5900 7000 7003
  121. SEEN-BY: 241/7005 7020 7042 7200 7300 7400 7503 7600 7903 243/10 16
  122. SEEN-BY: 243/20 22 91 244/10 11 20 21 24 26 28 37 40 50 70 90 245/2
  123. SEEN-BY: 245/5 51 53 54 55 56 57 505 551 555 5600 246/2 247/1 36 700
  124. SEEN-BY: 248/1 404 249/1 9 15 2405/1 3 4 9 10 13 44 100 110 999
  125.  
  126.